/////////////////////////////////////////////////////////////////////////////
// Name:        dgt_alltab.cpp
// Purpose:     
// Author:      Aleksey Plotnikov & Alla Nabatova
// Modified by: 
// Created:     18/04/2008 02:11:39
// RCS-ID:      
// Copyright:   Diamant Software
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dgt_alltab.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "dgt_alltab.h"
#include "dgt_PluginManager.h"
#include "dgt_StudioApp.h"
#include "dgt_StorePlugin.h"
#include "dgt_SyntezPlugin.h"
#include "dgt_OutPlugin.h"
////@begin XPM images
////@end XPM images


/*!
 * dgt_AllTab type definition
 */

IMPLEMENT_DYNAMIC_CLASS( dgt_AllTab, wxPanel )


/*!
 * dgt_AllTab event table definition
 */

BEGIN_EVENT_TABLE( dgt_AllTab, wxPanel )

////@begin dgt_AllTab event table entries
    EVT_GRID_CELL_LEFT_CLICK( dgt_AllTab::OnCellLeftClick )

////@end dgt_AllTab event table entries

END_EVENT_TABLE()


/*!
 * dgt_AllTab constructors
 */

dgt_AllTab::dgt_AllTab()
{
    Init();
}

dgt_AllTab::dgt_AllTab(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
    Init();
    Create(parent, id, pos, size, style);
}


/*!
 * dgt_AllTab creator
 */

bool dgt_AllTab::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
////@begin dgt_AllTab creation
    wxPanel::Create(parent, id, pos, size, style);
    CreateControls();
////@end dgt_AllTab creation
    return true;
}


/*!
 * dgt_AllTab destructor
 */

dgt_AllTab::~dgt_AllTab()
{
////@begin dgt_AllTab destruction
////@end dgt_AllTab destruction
}


/*!
 * Member initialisation
 */

void dgt_AllTab::Init()
{
////@begin dgt_AllTab member initialisation
    m_AllGrid = NULL;
    m_AboutPl = NULL;
////@end dgt_AllTab member initialisation
}


/*!
 * Control creation for dgt_AllTab
 */

void dgt_AllTab::CreateControls()
{    
////@begin dgt_AllTab content construction
    dgt_AllTab* itemPanel1 = this;

    this->SetName(_T("All"));
    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemPanel1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);

    m_AllGrid = new dgt_PluginGrid( itemPanel1, ID_DGT_PLUGINGRID, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
    m_AllGrid->SetFont(wxFont(10, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Tahoma")));
    m_AllGrid->SetDefaultColSize(50);
    m_AllGrid->SetDefaultRowSize(25);
    m_AllGrid->SetColLabelSize(25);
    m_AllGrid->SetRowLabelSize(50);
    m_AllGrid->CreateGrid(1, 5, wxGrid::wxGridSelectCells);
    itemBoxSizer3->Add(m_AllGrid, 1, wxGROW|wxALL, 5);

    m_AboutPl = new wxStaticText( itemPanel1, wxID_STATIC, _("Select a plugin"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
    itemBoxSizer2->Add(m_AboutPl, 0, wxALIGN_LEFT|wxALL, 5);

////@end dgt_AllTab content construction
	m_AllGrid->SetGridMode();
	m_AllGrid->SetCheckBox(1);
	m_AllGrid->InsertCols(0,1);
	m_AllGrid->SetColLabelValue(0, _T("Type"));
	m_AllGrid->SetColSize(0, 75);
	m_AllGrid->DeleteCols(5,1);
	m_AllGrid->SetColSize(3,245);
	SetPluginInfo();
}


/*!
 * Should we show tooltips?
 */

bool dgt_AllTab::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap dgt_AllTab::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin dgt_AllTab bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end dgt_AllTab bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon dgt_AllTab::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin dgt_AllTab icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end dgt_AllTab icon retrieval
}

/*************************************************************/
//Set info about plugin into the grid
void dgt_AllTab::SetPluginInfo()
{
	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	dgt_PluginInfo info;
	int row_numb = 0;
	short tPlugin_type = (short) PLUGIN_LOGIGAL;
	unsigned qRows = 1;

	for( short j = tPlugin_type; j<= (short) PLUGIN_OUT; j++ )
	{
		if( j == (short) PLUGIN_SYNTEZ )
			continue;
		
		int number = pManager->get_PluginCount( (PLUGIN_TYPE) j );
		if( !number )
			continue;
	
		int RowToAdd;
		if( qRows == 1)
			RowToAdd = number - 1;
		else
			RowToAdd = number;

		qRows += number;

		if( RowToAdd )
			m_AllGrid->AppendRows( RowToAdd );

		for( int i = number; i > 0; i-- )
		{ 
			dgt_Plugin_Ptr plugin = pManager->get_Plugin( (PLUGIN_TYPE) j , i - 1 );

			if( pManager->IsLoaded( i - 1 ))
			{
				m_AllGrid->SetCellValue( _T("1"), row_numb, 2 );
			}

			plugin->GetPluginInfo( info );
			wxString sDllName = pManager->get_PluginDllName((PLUGIN_TYPE) j, i - 1 );
			m_AllGrid->SetCellValue(sDllName,row_numb,1);

			wxString t_str = info.m_PluginName;
			m_AllGrid->SetCellValue(t_str,row_numb,3);

			t_str = info.m_Version;
			m_AllGrid->SetCellValue(t_str,row_numb,4);

			t_str = info.m_Description;
			array_string.Add(info.m_Description);
			
			short tType = (short) info.m_PluginType;
			if( tType == PLUGIN_LOGIGAL )
				t_str = _("LOGICAL");
			else if( tType == PLUGIN_OPERATION )
				t_str = _("OPERATION");
			else if( tType == PLUGIN_MEMORY )
				t_str = _("MEMORY");
			else if( tType == PLUGIN_TRIGGER )
				t_str = _("TRIGGER");
			else if( tType == PLUGIN_SYNTEZ_OA )
				t_str = _("SYNTEZ OA");
			else if( tType == PLUGIN_SYNTEZ_CA )
				t_str = _("SYNTEZ CA");
			else if( tType == PLUGIN_STORE )
				t_str = _("STORE");
			else if( tType == PLUGIN_OUT )
				t_str = _("OUT");

			m_AllGrid->SetCellValue( t_str, row_numb, 0 );

			m_AllGrid->SetReadOnly(row_numb,0);
			m_AllGrid->SetReadOnly(row_numb,1);
			m_AllGrid->SetReadOnly(row_numb,3);
			m_AllGrid->SetReadOnly(row_numb,4);
			row_numb++;
		}
	}
}


/*!
 * wxEVT_GRID_CELL_LEFT_CLICK event handler for ID_DGT_PLUGINGRID
 */
//load info about selected plugin into the static text
void dgt_AllTab::OnCellLeftClick( wxGridEvent& event )
{
	if (m_AllGrid->GetCellValue(0,0)!=_T(""))
	{
		wxString string;
		int n=event.GetRow();
		string = array_string.Item(n);
		m_AboutPl->SetLabel(string);
	}
	
	event.Skip();
}

